Date.prototype.toJSON() 您所在的位置:网站首页 date json Date.prototype.toJSON()

Date.prototype.toJSON()

2023-03-15 22:05| 来源: 网络整理| 查看: 265

Date instances refer to a specific point in time. toJSON() calls the object's toISOString() method, which returns a string representing the Date object's value. This method is generally intended to, by default, usefully serialize Date objects during JSON serialization, which can then be deserialized using the Date() constructor or Date.parse() as the reviver of JSON.parse().

The method first attempts to convert its this value to a primitive by calling its [@@toPrimitive]() (with "number" as hint), valueOf(), and toString() methods, in that order. If the result is a non-finite number, null is returned. (This generally corresponds to an invalid date, whose valueOf() returns NaN.) Otherwise, if the converted primitive is not a number or is a finite number, the return value of this.toISOString() is returned.

Note that the method does not check whether the this value is a valid Date object. However, calling Date.prototype.toJSON() on non-Date objects does not have well-defined semantics.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有